﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using System.Diagnostics;

namespace Genuilder.Extensibility.Tests
{
	public static class TestExtensions
	{
		[DebuggerHidden]
		public static void AssertHas(this IEnumerable<GenItem> items, params string[] itemsName)
		{
			foreach(var item in itemsName)
			{
				if(!items.Any(i => i.File.Name == item))
				{
					Assert.False(true, item + " not found in this GenItemCollection");
				}
			}
		}


		public static void AssertNoError(this RunResult result)
		{
			if(result.Error != null)
			{
				Assert.False(true, "error not expected : " + result.Error.Exception.Message);
			}
		}


		public static void AssertContainsOnly(this IEnumerable<string> actualValues, params string[] expectedValues)
		{
			foreach(var expectedValue in expectedValues)
			{
				var match = actualValues.Any(actual => actual == expectedValue);
				Assert.True(match, expectedValue + " not found in actualValues");
			}
			foreach(var actualValue in actualValues)
			{
				var match = expectedValues.Any(expected => expected == actualValue);
				Assert.True(match, actualValue + " should not be found");
			}
		}

		[DebuggerHidden]
		public static void AssertHas(this IEnumerable<GenItem> items, Func<GenItem, bool> predicate)
		{
			var pass = items.Any(i => predicate(i));
			if(!pass)
				Assert.False(true, "No GenItem satisfy this predicate");
		}

		[DebuggerHidden]
		public static void AssertHas(this IEnumerable<GenItem> genItems, string fileName, SourceType sourceType)
		{
			AssertHas(genItems, o => o.Name == fileName && o.SourceType == sourceType);
		}

		[DebuggerHidden]
		public static void AssertHasNot(this IEnumerable<GenItem> items, Func<GenItem, bool> predicate)
		{
			var pass = items.Any(i => !predicate(i));
			if(!pass)
				Assert.False(true, "A GenItem satisfy this predicate");
		}
	}
}
